package judesart.app.server;

import java.util.ArrayList;
import java.util.List;

import judesart.app.client.user.UserController;
import judesart.app.domain.User;
import judesart.app.repository.UserDAO;
import judesart.app.service.UserService;
import judesart.app.shared.ValidationException;
import judesart.common.bean.ApplicationContextProvider;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class UserControllerImpl extends RemoteServiceServlet implements
        UserController
{
    UserDAO userDAO = ApplicationContextProvider.getCtx().getBean(UserDAO.class);
    UserService userService = ApplicationContextProvider.getCtx().getBean(
            UserService.class);

    @Override
    public User createUser(User user) throws ValidationException
    {
        return userDAO.createUser(user);
    }

    @Override
    public List<User> searchUsers()
    {
        List<User> users = userDAO.findAllUsers();
        return new ArrayList<User>(users);
    }

    @Override
    public User getUser(Long id)
    {
        return userDAO.findUserById(id);
    }

    @Override
    public User updateUser(User user) throws ValidationException
    {
        return userDAO.updateUser(user);
    }

    @Override
    public void deleteUser(Long id)
    {
        userDAO.deleteUser(id);
    }

    @Override
    public User getCurrentUser()
    {
        return userService.getCurrentUser();
    }

    @Override
    public User getFeaturedArtist()
    {
        return userDAO.findFeatured();
    }
}
